<template>
  <el-form-item :label="textLabel+'：'">
    <el-select v-if="enumKey" v-model="query.text" :placeholder="'请选择'+textLabel" :clearable="clearable">
      <el-option v-for="(item,index) in enums" :key="index" :label="item.dataText" :value="item.dataCode"></el-option>
    </el-select>
    <el-select v-else v-model="query.text" :placeholder="'请选择'+textLabel" :clearable="clearable">
      <el-option v-for="(item,index) in dicData" :key="index" :label="item.desc" :value="item.val"></el-option>
    </el-select>
  </el-form-item>
</template>

<script>
export default {
  props:{
    text:{
      type:String,
      default:''
    },
    textLabel:{
      type:String,
      default:''
    },
    isClear:{
      type:Boolean,
      default:false
    },
    enumKey:{
      type:String,
      default:''
    },
    dicData:{
      type:Array,
      default:function(){
        return []
      },
    },
    clearable:{
      type:Boolean,
      default:true
    },
  },
  watch:{
    'query.text':function(n){
      this.$emit("getData",n,this.text)
    },
    'isClear':function(){
      this.query.text=''
    },
    'dicData':{
      handler(){
        this.query.text=''
      },
      deep:true
    },
  },
  data(){
    return{
      query:{
        text:''
      },
      enums:[]
    }
  },
  created(){
    const enumDatas=JSON.parse(sessionStorage.getItem("s-dictionary")).content
    this.enums=enumDatas[this.enumKey]
  },
  methods:{
  },
}
</script>

<style>

</style>